package com.dingding.special.order.route.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.dingding.common.core.amap.dto.ResGetMapShowRoute;
import com.dingding.common.core.amap.service.IAmapService;
import com.dingding.common.core.base.dto.AbstractValiResponse;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.common.core.util.paravalidate.ValiResult;
import com.dingding.common.core.util.paravalidate.ValidateUtil;
import com.dingding.special.order.route.dto.ReqGetMapShowRoute;
import com.dingding.special.order.route.service.IRecommendedRouteService;

/**
 * 
 * @ClassName: IOrderRouteService 
 * @Description: 用户下单后，调用高德API获取推荐路线
 * @author CHEHAUNBO 
 * @date 2016年9月5日 下午8:54:49
 * @since V2.4.0
 * 
 */
@Component("recommendedRouteService")
public class RecommendedRouteServiceImpl extends AbstractValiResponse implements IRecommendedRouteService {

	private static Logger log = Logger.getLogger(RecommendedRouteServiceImpl.class);

	@Resource(name = "amapService")
	private IAmapService amapService;

	/**
	 * 
	 * 通过用户位置获取推荐路线
	 * 
	 * @Title: getRecommendRouteList 
	 * @author CHEHAUNBO
	 * @since V2.4.0
	 * 
	 */
	@Override
	public ResponseEntity<List<ResGetMapShowRoute>> getRecommendRouteByPosition(ReqGetMapShowRoute reqGetMapShowRoute) {

		ValiResult valiResult = ValidateUtil.validateBeanIsAvaliable(reqGetMapShowRoute, ReqGetMapShowRoute.class);

		if (!valiResult.isAvailable()) {
			return super.error(valiResult);
		}

		List<ResGetMapShowRoute> resGetMapShowRoutes = null;
		try {
			resGetMapShowRoutes = amapService.getMapShowRoute(reqGetMapShowRoute.getOrigin(),
					reqGetMapShowRoute.getDestination());
		} catch (Exception e) {
			log.error("调用高德地图获取推荐路线出现异常！", e);
		}

		return super.success(resGetMapShowRoutes, HttpStatus.SC_OK);
	}

}
